/**
 * 
 */
package com.sri.business.search;

import java.sql.SQLException;
import java.util.List;

import com.sri.db.dao.search.SearchDAO;
import com.sri.db.dao.search.SearchDAOServiceFactory;
import com.sri.formBeans.SearchForm;
import com.sri.model.home.Home;
import com.sri.model.search.Search;

/**
 * @author skodali
 * 
 */
public class SearchManager {
  public static String searchHomesFile(SearchForm form) {
    SearchDAO searchDAO = SearchDAOServiceFactory.getSearchDAO();
    // searchDAO.getHome();
    // TODO find out the results file and return the content as a string. create a
    // new file, if it doesn't exist
    return "";
  }

  public static List searchHomes(SearchForm form) {
    SearchDAO searchDAO = SearchDAOServiceFactory.getSearchDAO();
    try {
      return searchDAO.getHomes(populateSearch(form));
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
  
	public static List<Home> getALLHomes() throws SQLException {
	  SearchDAO searchDAO = SearchDAOServiceFactory.getSearchDAO();
		  return searchDAO.getAllHomes();
  }

  private static Search populateSearch(SearchForm searchform) {
    Search searchBean = new Search();
    searchBean.setCityId(Integer.parseInt(searchform.getCity()));
    searchBean.setCountry(searchform.getCountry());
    searchBean.setLocation(searchform.getLocation());
    searchBean.setRentRange(Integer.parseInt(searchform.getRentRange()));
    searchBean.setStateId(Integer.parseInt(searchform.getState()));
    return searchBean;
  }
}
